using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MyMES.Dto;
using MyMES.IServices.MeadingManage;
using System.Threading.Tasks;
using VOL.Core.Controllers.Basic;
using VOL.Core.Filters;
using VOL.Core.Utilities.Response;
using VOL.Entity.AttributeManager;
using VOL.Entity.DomainModels.Core;
using VOL.Entity.MeadingManage;

namespace VOL.WebApi.Controllers.MyMES
{
    /// <summary>
    /// 工单管理控制器
    /// </summary>
    [Route("api/WorkOrder")]
    [ApiController]
    [AllowAnonymous] // 允许匿名访问
    [PermissionTable(Name = "WorkOrder")]
    public class WorkOrderController : ApiBaseController<IWorkOrderService>
    {
        private readonly IWorkOrderService _workOrderService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="workOrderService">工单服务</param>
        public WorkOrderController(IWorkOrderService workOrderService)
            : base(workOrderService)
        {
            _workOrderService = workOrderService;
        }

        /// <summary>
        /// 获取工单列表
        /// </summary>
        /// <param name="dto">查询条件</param>
        /// <returns>工单列表</returns>
        [HttpPost("GetWorkOrder")]
        public async Task<PageGridData<WorkOrder>> GetWorkOrder([FromBody] GetWorkOrderPageDto dto)
        {
            return await _workOrderService.GetWorkOrder(dto);
        }

        /// <summary>
        /// 创建工单
        /// </summary>
        /// <param name="workOrder">工单信息</param>
        /// <returns>操作结果</returns>
        [HttpPost("CreateWorkOrder")]
        public async Task<WebResponseContent> CreateWorkOrder([FromBody] WorkOrder workOrder)
        {
            return await _workOrderService.CreateWorkOrder(workOrder);
        }

        /// <summary>
        /// 更新工单
        /// </summary>
        /// <param name="workOrder">工单信息</param>
        /// <returns>操作结果</returns>
        [HttpPost("UpdateWorkOrder")]
        public async Task<WebResponseContent> UpdateWorkOrder([FromBody] WorkOrder workOrder)
        {
            return await _workOrderService.UpdateWorkOrder(workOrder);
        }

        /// <summary>
        /// 删除工单
        /// </summary>
        /// <param name="ids">工单ID列表，以逗号分隔的字符串</param>
        /// <returns>操作结果</returns>
        [HttpPost("DelWorkOrder")]
        public async Task<WebResponseContent> DelWorkOrder([FromQuery] string ids)
        {
            return await _workOrderService.DelWorkOrder(ids);
        }
    }
} 